package Factory;

import java.util.ArrayList;
import java.util.Random;


import tree.Node;
import tree.TreeNodesManager;
import tree.nodeType.Boolean.functions.AndOperator;
import tree.nodeType.Boolean.functions.NotOperator;
import tree.nodeType.Boolean.functions.OrOperator;
/**
 * factory of boolean nodes with boolean sons (And,Or,Not)
 *
 */

public class BooleanBooleanSonsFactory {
	private ArrayList<Factory>booleanFactories;
	private Random random;
	
	private class AndFactory implements Factory{

		@Override
		public Node createNode(Node parent, int depth, int maxDepth, TreeNodesManager treeNodesManager) {
			if (depth+2<=maxDepth){
				return new AndOperator(parent,depth,maxDepth,treeNodesManager);
			}
			return null;
		}
		
	}
	private class OrFactory implements Factory{

		@Override
		public Node createNode(Node parent, int depth, int maxDepth, TreeNodesManager treeNodesManager) {	
			if (depth+2<=maxDepth){
				return new OrOperator(parent,depth,maxDepth,treeNodesManager);
			}
			return null;
		}
	}
	
	private class NotFactory implements Factory{

		@Override
		public Node createNode(Node parent, int depth, int maxDepth, TreeNodesManager treeNodesManager) {
			if (depth+2<=maxDepth){
				return new NotOperator(parent,depth,maxDepth,treeNodesManager);
			}
			return null;
		}
		
	}
	public BooleanBooleanSonsFactory() {
		booleanFactories=new ArrayList<Factory>();
		booleanFactories.add(new AndFactory());
		booleanFactories.add(new NotFactory());
		booleanFactories.add(new OrFactory());
		random=new Random();
	}
	public Node createRandomNode(Node parent, int depth, int maxDepth,TreeNodesManager treeNodesManager){
		return booleanFactories.get(random.nextInt(booleanFactories.size()))
			.createNode(parent, depth, maxDepth,treeNodesManager);		
	}
}
